package com.charity.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.charity.domain.Donation;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;

@Mapper
public interface DonationMapper extends BaseMapper<Donation> {
    /**
     * 查询用户的捐赠记录
     * @param userId 用户ID
     * @param offset 偏移量
     * @param pageSize 每页数量
     * @return 捐赠记录列表
     */
    @Select("SELECT * FROM charity_donation WHERE user_id = #{userId} ORDER BY create_time DESC LIMIT #{offset}, #{pageSize}")
    List<Donation> selectByUserId(@Param("userId") Long userId, @Param("offset") int offset, @Param("pageSize") int pageSize);

    /**
     * 查询项目的捐赠记录
     * @param projectId 项目ID
     * @param offset 偏移量
     * @param pageSize 每页数量
     * @return 捐赠记录列表
     */
    @Select("SELECT * FROM charity_donation WHERE project_id = #{projectId} ORDER BY create_time DESC LIMIT #{offset}, #{pageSize}")
    List<Donation> selectByProjectId(@Param("projectId") Long projectId, @Param("offset") int offset, @Param("pageSize") int pageSize);

    /**
     * 查询项目的总捐赠金额
     * @param projectId 项目ID
     * @return 总金额
     */
    @Select("SELECT SUM(amount) FROM charity_donation WHERE project_id = #{projectId}")
    Double selectProjectTotalAmount(@Param("projectId") Long projectId);

    /**
     * 查询用户的总捐赠金额
     * @param userId 用户ID
     * @return 总金额
     */
    @Select("SELECT SUM(amount) FROM charity_donation WHERE user_id = #{userId}")
    Double selectUserTotalAmount(@Param("userId") Long userId);
}